import axios from 'axios'
var qs = require('qs')

const debug = process.env.NODE_ENV !== 'production'

let base = debug ? 'api' : 'shareCars'
// get请求封装
function getAxios (url) {
  return params => axios.get(`${base}${url}`, {
    params: params
  }).then(res => res.data)
}
// if (typeof res.data.data === 'string') {
//   return JSON.parse(res.data.data)
// }

// // post请求封装
function postAxios (url) {
  return params => axios.post(`${base}${url}`, qs.stringify(params)).then(res => res.data)
}
// 表单数据提交
function formAxios (url) {
  var config = {
    headers: {
      'content-type': 'multipart/form-data'
    }
  }
  return formData => axios.post(`${base}${url}`, formData, config).then(res => res.data)
}
export const get = getAxios
export const post = postAxios
export const form = formAxios
